enum ThingShareValidationType {
  forever,
  period;

  /// 从 int 转 enum
  static ThingShareValidationType fromInt(int value) {
    switch (value) {
      case 0:
        return ThingShareValidationType.forever;
      case 1:
        return ThingShareValidationType.period;
      default:
        return ThingShareValidationType.forever;
    }
  }

  /// 转成原生的 int 值
  int get rawValue {
    switch (this) {
      case ThingShareValidationType.forever:
        return 0;
      case ThingShareValidationType.period:
        return 1;
    }
  }
}

class ThingSmartShareMemberModel {
  final int memberId;
  final String nickName;
  final String userName;
  final String iconUrl;
  final ThingShareValidationType shareMode;
  final int endTime;
  final String uid;

  ThingSmartShareMemberModel({
    required this.memberId,
    required this.nickName,
    required this.userName,
    required this.iconUrl,
    required this.shareMode,
    required this.endTime,
    required this.uid,
  });

  /// 从 iOS 传来的 Map 转换（Map 通常来自 MethodChannel）
  factory ThingSmartShareMemberModel.fromJson(Map<String, dynamic> json) {
    return ThingSmartShareMemberModel(
      memberId: json['memberId'] ?? 0,
      nickName: json['nickName'] ?? '',
      userName: json['userName'] ?? '',
      iconUrl: json['iconUrl'] ?? '',
      shareMode: ThingShareValidationType.fromInt(json['shareMode'] ?? 0),
      endTime: json['endTime'] ?? 0,
      uid: json['uid'] ?? '',
    );
  }

  /// 转换为 Map，可回传给原生
  Map<String, dynamic> toJson() {
    return {
      'memberId': memberId,
      'nickName': nickName,
      'userName': userName,
      'iconUrl': iconUrl,
      'shareMode': shareMode.rawValue,
      'endTime': endTime,
      'uid': uid,
    };
  }

  @override
  String toString() {
    return 'ThingSmartShareMemberModel(memberId: $memberId, nickName: $nickName, userName: $userName, '
        'iconUrl: $iconUrl, shareMode: $shareMode, endTime: $endTime, uid: $uid)';
  }
}
